home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / cfuncs.zip / GRANGE.C < prev    next >
Text File  |  1991-05-20  |  2KB  |  83 lines

  1. #include "funcs.h"
  2. extern int FG, BG;
  3. /*---------------------- getrange-------------------------------*/
  4. /*DESCRIPTION:    This funcion get startng and ending ranges.    */
  5. /*                                */
  6. /*INPUT:                            */
  7. /*    prompt = prompt All Entries?                          */
  8. /*    total = total number to select                      */
  9. /*    start = starting number of range                    */
  10. /*    stop = ending number of range                       */
  11. /*RETURNS 0 on success                        */
  12. /*       -1 on invalid entry or escape                */
  13. /*USES: GetCursor, SetCursor, OffCursor, OnCursor, Frame    */
  14. /*IN: grange.c                            */
  15. /*--------------------------------------------------------------*/
  16.  
  17. getrange(char *prompt, int total, int *start, int *stop)
  18.  
  19. {
  20.     int    ans;
  21.     char    buff[36];
  22.     FrameDataType    Fr;
  23.     unsigned int  OldCursor;
  24.  
  25.     if(total <=0) return(-1);
  26.  
  27.     OldCursor = GetCursor();
  28.     OffCursor();
  29.  
  30.     Fr.clear = 2;
  31.     Frame(&Fr);
  32.  
  33.     Fr.X = 25; Fr.Y = 6;
  34.     Fr.F = (FG==-1)? 7: FG;
  35.     Fr.B = (BG==-1)? 5: BG;
  36.     Fr.L = 5; Fr.W = 36;
  37.     Fr.txt[1] = buff;
  38.     sprintf(Fr.txt[1], "  %s All Entries? (Y/N)", prompt);
  39.     Frame(&Fr);
  40.  
  41.     do
  42.     {
  43. /*--------LOOP UNTIL 'Y' OR 'N' OR ESC-------------*/
  44.         gotoxy(54, 8);
  45.         ans = toupper(getch());
  46.         if (ans == 27)
  47.             return(-1);
  48.         if (ans == 'Y')
  49.         {
  50.             *start = 1;
  51.             *stop = total;
  52.         }
  53.  
  54.         if (ans == 'N')
  55.         {
  56.             OnCursor();
  57.             Fr.X = 23; Fr.Y = 7;
  58.             Fr.F = 7; Fr.B = 1;
  59.             Fr.L = 10; Fr.W = 34;
  60.             Fr.txt[1] = buff;
  61.             sprintf(Fr.txt[1], "   There are %d to %s", total, prompt);
  62.             Fr.txt[3] = "     Starting at --> ";
  63.             Fr.txt[5] = "     Stopping at --> ";
  64.             Frame(&Fr);
  65.             gotoxy(45, 11);
  66.             scanf("%d", start);
  67.             gotoxy(45, 13);
  68.             scanf("%d", stop);
  69.  
  70.             if (*start < 0 || *stop < 0 || *start > total)
  71.             {
  72.                 SetCursor(OldCursor);
  73.                 return(-1);
  74.             }
  75.             if (*stop > total)
  76.                 *stop = total;
  77.         }
  78.     } while(ans != 'Y' && ans != 'N');
  79.  
  80.     SetCursor(OldCursor);
  81.     return(0);
  82. }
  83.